﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel.DataAnnotations;

namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        private Interval interval;
        BindToolkit.BindWrapper wrapper;
        public MainPage()
        {
            InitializeComponent();
            interval=new Interval() { InnerInterval = new Interval() };
            wrapper = new BindToolkit.BindWrapper(interval, true);
            this.DataContext = wrapper;
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            wrapper.ValidateWholeObject(null);
        }
        private ValidationException FakeException(string field, string message)
        {
            return new ValidationException(
                new System.ComponentModel.DataAnnotations.ValidationResult(message, new string[] { field }),
                null, null);


        }
        private void InnerGrid_BindingValidationError(object sender, ValidationErrorEventArgs e)
        {
            e.Handled = true;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            wrapper.AddRemoteErrors(new ValidationException[] { FakeException("InnerInterval.Low", "fake remote error") });
        }

        

        
    }
}
